/**
 *
 * 2007-11-6 下午01:11:33
 * @author xuhuan
 */

package edu.ccut.saturn.studio.wfg.part;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;

import edu.ccut.saturn.studio.wfg.figure.SaturnFigure;

public class NodeCellEditorLocator implements CellEditorLocator {
	
	private Figure figure;

	public NodeCellEditorLocator(Figure figure) {
		this.figure = figure;
	}

	public void relocate(CellEditor celleditor) {

		Text text = (Text) celleditor.getControl();
		Point pref = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		if (figure instanceof SaturnFigure) {
			Rectangle rect = ((SaturnFigure) this.figure).getTextBounds();
			text.setBounds(rect.x - 1, rect.y - 1, pref.x + 1, pref.y + 1);
		}
	}
}
